<?php
namespace app\admin\validate;

use think\Validate;

class PayCoinsValidate extends Validate
{

    protected $rule = [
        'coin_name' => 'require|unique:PayCoins',
        "id" => 'require',
        "icon" => 'require',
        "address" => 'require',
        "sort"=>'require|number',
        "pay_status" => 'require|in:1,-1',
        "fee_type" => 'require|in:1,2',
        'network' => 'require',
        'pay_min_num' => 'require|checkNumber',
        'withdraw_min_num' => 'require|checkNumber',
        'withdraw_max_num' => 'require|checkNumber',
        'fee' => 'require|checkNumber',
        'withdraw_status' => 'require|in:1,-1',
    ];

    protected $message = [
        'coin_name.require' => '币种名称必须填写',
        'coin_name.unique' => '币种已经存在',
        "id.require" => "缺少id",
        "address.require"=>"充值地址必须填写",
        "sort.require"=>"排序必须填写",
        "sort.number"=>"排序必须是数字",
        "pay_status.in" => "充值状态值错误",
        "pay_status.require" => "缺少充值状态值",
        "withdraw_status.in" => "提现状态值错误",
        "withdraw_status.require" => "缺少提现状态值",
        "fee_type.require" => "确少手续费类型",
        "fee_type.in" => "手续费类型错误",
        "fee.require" => "缺少手续费",
        "fee.checkNumber" => "手续费类型必须是数字",
        "network.require" => "确少充值网络",
        "withdraw_min_num.require" => "缺少最小提币数量",
        "withdraw_min_num.checkNumber" => "最小提币数量必须是数字",
        "withdraw_max_num.require" => "缺少最大提币数量",
        "withdraw_max_num.checkNumber" => "最大提币数量必须是数字",
    ];

    protected $scene = [
        'add' => ['coin_name','sort','icon','pay_status','fee_type','network','pay_min_num','withdraw_min_num','withdraw_max_num','fee','withdraw_status'],
        'edit' => ['id','coin_name','sort','icon','pay_status','fee_type','network','pay_min_num','withdraw_min_num','withdraw_max_num','fee','withdraw_status']
    ];

    protected function checkNumber($value)
    {
       if (!is_numeric($value)) {
           return false;
       }
       if ($value<0) {
           return false;
       }
       return true;
    }

}